package com.uniquindio.proyectomoviles;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class Login extends Activity {

	private TextView lblGotoRegister;
	private Button btnLogin;
	private EditText inputEmail;
	private EditText inputPassword;
	private TextView loginErrorMsg;
	
	
	private BinderService binderService;
	
	private ServiceConnectionForBinder sForBinder = new ServiceConnectionForBinder(
			this);

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);

		inputEmail = (EditText) findViewById(R.id.txtEmail);
		inputPassword = (EditText) findViewById(R.id.txtPass);
		btnLogin = (Button) findViewById(R.id.btnLogin);
		loginErrorMsg = (TextView) findViewById(R.id.login_error);
		lblGotoRegister = (TextView) findViewById(R.id.btnRegister);
		
	}
	
	@Override
	protected void onStart() {
		super.onStart();
		Log.i("ServicesExamples", "on start eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
		Intent intent = new Intent(this, BinderService.class);
		bindService(intent, sForBinder, BIND_AUTO_CREATE);
		
	}
	
	@Override
	protected void onStop() {
		super.onStop();

		try {
			unbindService(sForBinder);
		} catch (Exception e) {
			e.printStackTrace();
			Log.e("ServicesExamples", "No se puede desligar el servicio.");
		}
	}
	
	public void onClickLinkToRegister(View view) {
		Log.i("ServicesExamples", "Registro aaaaaaaaaaaaaaaaaaaaaaaaaa");

		Intent intent = new Intent(this, Registro.class);
		startActivity(intent);
	}
	
	public void onClickLinkToLogin(View view) {
		
		Log.i("ServicesExamples", "Desde el Hilo principal");

		if (binderService != null) {
			binderService.consumeTweetsAndCreateNotification(this);
		}
		
		Log.i("ServicesExamples", "Desde el Hilo principal 2");
		//Intent intent = new Intent(this, Registro.class);
		//startActivity(intent);
	}
	
	
	
	public void setBinderService(BinderService binderService) {
		this.binderService = binderService;
	}

	
}
